package com.ccloud.gen.engine.base;

import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.ccloud.gen.engine.config.*;
import lombok.Data;

/**
 * @Version V1.0
 * @Project bigdata-cloud
 * @Title AbstractTemplateEngine
 * @Description 模板生成父类
 * @Package com.ccloud.gen.engine.base
 * @Date 2021/7/8 3:33 下午
 * @Copyright: 武汉大数据产业发展有限公司 All rights reserved.
 */
@Data
public class AbstractTemplateEngine {

    protected ContextConfig contextConfig;                //全局配置
    protected ControllerConfig controllerConfig;          //控制器的配置
    protected PageConfig pageConfig;                      //页面的控制器
    protected MapperConfig mapperConfig;                        //Dao配置
    protected ServiceConfig serviceConfig;                //Service配置
    protected SqlConfig sqlConfig;                        //sql配置
    protected TableInfo tableInfo;                        //表的信息

    public void initConfig() {
        if (this.contextConfig == null) {
            this.contextConfig = new ContextConfig();
        }
        if (this.controllerConfig == null) {
            this.controllerConfig = new ControllerConfig();
        }
        if (this.pageConfig == null) {
            this.pageConfig = new PageConfig();
        }
        if (this.mapperConfig == null) {
            this.mapperConfig = new MapperConfig();
        }
        if (this.serviceConfig == null) {
            this.serviceConfig = new ServiceConfig();
        }
        if (this.sqlConfig == null) {
            this.sqlConfig = new SqlConfig();
        }
        this.contextConfig.init();

        this.controllerConfig.setContextConfig(this.contextConfig);
        this.controllerConfig.init();

        this.serviceConfig.setContextConfig(this.contextConfig);
        this.serviceConfig.init();

        this.mapperConfig.setContextConfig(this.contextConfig);
        this.mapperConfig.init();

        this.pageConfig.setContextConfig(this.contextConfig);
        this.pageConfig.init();

        this.sqlConfig.setContextConfig(this.contextConfig);
        this.sqlConfig.init();
    }
}

